<!--
 * @Author: rogi
 * @Date: 2022-07-18 08:45:13
 * @LastEditTime: 2022-12-19 14:23:33
 * @LastEditors: rogi
 * @Description: 描述
-->
<script setup>
import { onMounted, ref, computed } from "vue";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
const language = ref("zh-cn");
const refresh = ref(false)
const locale = computed(() => (language.value === "zh-cn" ? zhCn : en));

import WhrWebSocket from "../scripts/websoket";
import { host } from "@/utils/config.js";
import { getUserInfo } from "@/api/user.js";
import { read } from "@/utils/storage";
import sdk from '@/sdk/index'
import { getQueryStrings } from "@/utils/tool.js";
import { searchOneselfMenuAll, getButtonAll } from '@/api/menu.js'
import { useStore } from 'vuex';
import { useRouter } from 'vue-router'

const store = useStore()
const router = useRouter()
sdk.init()
const socket = ref(null);
const getMenu = async (infoId) => {
  const menu = await searchOneselfMenuAll({
    parentId: sessionStorage.getItem('parentId')
  })
  const newList = []
  function init (list) {
    list.forEach((el) => {
      newList.push(el)
      if (el.children && el.children.length) {
        init(el.children)
      }
    })
  }
  init(menu.data)
  store.commit('common/SET_MENU', newList)

  // console.log('infoId', infoId)
// return false
  if (infoId) {
    setTimeout(() => {
      router.push({
        path:'/productDetail',
        query:{
          fundProductId: infoId
        }
      })
    }, 50)
  }
}
const getAllBtns = async () => {
  const menu = await getButtonAll()
  const newList = {}
  menu.data.forEach((el) => {
    for (let k in el) {
      let item = {}
      el[k].forEach((val) => {
        item[val.perms] = val
      })
      newList[k] = item
    }
  })
  store.commit('common/SET_BURROM_All', newList)
}
onMounted(async () => {
  const res = getQueryStrings(window.location.search)
  for (let k in res) {
    sessionStorage.setItem(k, res[k])
  }
  getMenu(res.infoId)
  getAllBtns()

  // console.log('res.parentId', res.parentId)
  // if (!sessionStorage.getItem('access_token')) {
  //   console.log('wwwwwwwwwwwww')
  //   const res = await sdk.getUserInfo()
  //   sessionStorage.setItem('access_token', res.data.access_token)
  //   sessionStorage.setItem('enterprise_id', res.data.enterprise_id)
  //   sessionStorage.setItem('expires_in', res.data.expires_in)
  //   sessionStorage.setItem('user_id', res.data.user_id)
  //   sessionStorage.setItem('user_type', res.data.user_type)
  //   window.location.href = '/'
  // }
  document.body.style.setProperty("--el-color-primary", "#0054FE");
  document.body.style.setProperty("--el-disabled-bg-color", "#F2F3F5");
  document.body.style.setProperty("--el-disabled-border-color", "#F2F3F5");
  document.body.style.setProperty("--el-input-border-color", "#C9CDD4");
  document.body.style.setProperty("--el-border-color", "#C9CDD4");
  document.body.style.setProperty("--el-text-color-regular", "#1D2129");
  document.body.style.setProperty("--el-input-border-radius", "5px");
  document.body.style.setProperty("--el-border-radius-base", "6px");
  document.body.style.setProperty("--el-border-radius-small", "5px");
  document.body.style.setProperty("--el-pagination-button-bg-color", "#fff");
  document.body.style.setProperty("--el-fill-color", "#fff");

  document.body.style.setProperty("--el-menu-active-color", "#2B4985");
  document.body.style.setProperty("--el-menu-base-level-padding", "20px");
  document.body.style.setProperty("--el-menu-level-padding", "10px");
  document.body.style.setProperty("--el-dialog-padding-primary", "30px");

  document.body.style.setProperty("--el-component-size", "34px");
  // tag
  document.body.style.setProperty("--el-tag-bg-color", "#e5f7e8");
  document.body.style.setProperty("--el-color-success", "#16a932");
  document.body.style.setProperty("--el-color-warning-light-9", "#fff2e6");
  document.body.style.setProperty("--el-color-warning", "#ea7f26");
  document.body.style.setProperty("--el-color-danger-light-9", "#feeceb");
  document.body.style.setProperty("--el-color-danger", "#dc4d51");

  // const userId = read("userInfo").id;
  // var url =
  //   host.requestHost.replace("https://", "ws://").replace("http://", "ws://") +
  //   "/jeecg-boot/websocket/" +
  //   userId;
  // socket.value = new WhrWebSocket({
  //   path: url,
  //   onmessage: function (msg) {
  //     console.log(msg);
  //   },
  // });
});
</script>

<template>
  <el-config-provider :locale="locale">
    <router-view></router-view>
  </el-config-provider>
</template>

<style scoped>
:root {
  --el-date-editor-width: 100% !important;
}
</style>
